package com.css.bjdt_report.util;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.entity.Record;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.context.support.WebApplicationObjectSupport;

@Controller
public class SystemSetup extends WebApplicationObjectSupport{

	@Autowired
	private Dao dao;

	//查询数据字典表
	@Cacheable(value = "codedic")
	public Map<String, Map<String, String>> queryCodedic() {
		Map<String, Map<String, String>> codeMap = new HashMap<String, Map<String, String>>();
		List<Record> list = dao.query("STAT_T_CODE", Cnd.orderBy().asc("section").asc("code"));
		for (Record r : list) {
			String section = r.getString("section");
			Map<String, String> sectionCodeMap = codeMap.get(section);
			if (sectionCodeMap == null) {
				sectionCodeMap = new LinkedHashMap<String, String>();
				codeMap.put(section, sectionCodeMap);
			}
			sectionCodeMap.put(r.getString("code"), r.getString("code_name"));
		}
		getServletContext().setAttribute(SystemContext.CODEDIC, codeMap);
		return codeMap;
	}

}
